<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>批量地址</title>
    <style type="text/css">
      body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
      /*修改了地图大小*/
      #l-map{height:100%;width:100%;}
      #r-result{width:100%; font-size:14px;line-height:20px;}
    </style>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=r3jUcdWlYEVGd7Nx83YvGCC0IdPMg9hY"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body>
    <div id="l-map"></div>
    <div id="r-result"><div id="result" hidden="hidden"></div></div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("l-map");
    //修改了地图级别,方便展示
    map.centerAndZoom(new BMap.Point(114.311582,30.598467), 5);
    map.enableScrollWheelZoom(true);
    var index = 0;
    var myGeo = new BMap.Geocoder();
    var adds = [];

    findAddress();   //异步调用

    window.onload=function(){   //入口函数
        bdGEO();
    };
    function findAddress() {
        var param={
            "type":"post",
            "url":"/address/findAllAddress.do",
            "dataType":'json',
            "success":function (response) {
                adds=response.data;
            },
            "error":function () {
                alert(date.message);
            }
        }
        $.ajax(param);
    }
    function bdGEO(){
        if (index < adds.length) {
            var add = adds[index];
            geocodeSearch(add);
            index++;
        }
    }
    function geocodeSearch(add){
        if(index < adds.length){
            setTimeout(window.bdGEO,400);
        }
        myGeo.getPoint(add, function(point){
            if (point) {
                document.getElementById("result").innerHTML +=  index + "、" + add + ":" + point.lng + "," + point.lat + "</br>";
                var address = new BMap.Point(point.lng, point.lat);
                addMarker(address,new BMap.Label(index+":"+add,{offset:new BMap.Size(20,-10)}));
            }
        }, "武汉市");
    }
    // 编写自定义函数,创建标注
    function addMarker(point,label){
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        marker.setLabel(label);
    }

</script>
